package tree.binary;

import entity.tree.TreeNode;

public class leetcode404左叶子之和 {
    public int sumOfLeftLeaves(TreeNode root) {
        // 只有根节点时，不算做左叶子结点
        return dfs(root, 1);
    }

    public int dfs(TreeNode root, int type) {
        int sum = 0;
        if (root == null) {
            return sum;
        }
        if (root.left == null && root.right == null && type == 0) {
            return root.val;
        }
        sum += dfs(root.left, 0);
        sum += dfs(root.right, 1);
        return sum;
    }
}
